
/**
  * 删除括号中的牌号
  * 删除3和6中间 的4
  * */
object RemovePH extends App {
  val a = List(1, 4, 2, 3, 4, 5, 6, 4, 7, 8)
  val delete = 4
  val rk: Int = 6
  val lk: Int = 3

  val deleteIndexs = a.zipWithIndex.filter(_._1 == 4).map(_._2)

  //2,4,7 => 2,false 4 ture 7 false
  val deleteIndexes = deleteIndexs.map(f = deleteIndex => {
    val (head, tail) = a.splitAt(deleteIndex)
    val headCurrect = head.map(x => {
      x match {
        case `rk` => -1
        case `lk` => 1
        case _ => 0
      }
    }).sum
    val tailCurrect = tail.map {
      case `rk` => -1
      case `lk` => 1
      case _ => 0
    }.sum

    (deleteIndex, headCurrect + tailCurrect == 0 && headCurrect > 0)

  }).filter(_._2 ==true).map(_._1)


  println(a.zipWithIndex.filterNot(x=>deleteIndexes.contains(x._2)).map(_._1))
}
